import { createRequire } from 'module'
import { defineConfig, type DefaultTheme } from 'vitepress'

const require = createRequire(import.meta.url)
const pkg = require('vitepress/package.json')

export const en = defineConfig({
  lang: 'en-US',
  description: 'Digital Signage',

  themeConfig: {
    nav: nav(),

    sidebar: {
      '/en/guide/': { base: '/en/guide/', items: sidebarGuide() },
      '/en/dev/': { base: '/en/dev/', items: sidebarDev() },
      '/en/reference/': { base: '/en/reference/', items: sidebarReference() }
    },

    // editLink: {
    //   pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
    //   text: 'Edit this page on GitHub'
    // },

    footer: {
      message: '',
      copyright: `<span style="font-size:6px;color:transparent;">Copyright © 2016-${new Date().getFullYear()} KzzMedia.</span>`
    },

    docFooter: {
      prev: 'Previous',
      next: 'Next'
    },

    outline: {
      label: 'On this page'
    },

    lastUpdated: {
      text: 'Updated at',
      formatOptions: {
        dateStyle: 'short',
        timeStyle: 'medium'
      }
    },

    langMenuLabel: 'Languages',
    returnToTopLabel: 'Back to top',
    sidebarMenuLabel: 'Menu',
    darkModeSwitchLabel: 'Theme',
    lightModeSwitchTitle: 'Switch to light mode',
    darkModeSwitchTitle: 'Switch to dark mode'
  }
})

function nav(): DefaultTheme.NavItem[] {
  return [
    {
      text: 'Developer',
      link: '/en/dev/intro',
      activeMatch: '/en/dev/'
    }
  ]
}

function sidebarGuide(): DefaultTheme.SidebarItem[] {
  return [
    {
        text: 'Quick Start',
        collapsed: false,
        items: [
            { text: 'Cloud Casting', link: 'cast_cloud' },
            { text: 'Local Casting - LAN Direct', link: 'cast_lan_direct' },
            { text: 'Local Casting - Private Deployment', link: 'cast_lan_deploy' },
            { text: 'USB Disk Play', link: 'cast_ext' },
            { text: 'Select Folder Play', link: 'cast_dir' }
        ]
    },
    {
      text: 'Player Manual',
      collapsed: false,
      items: [
        { text: 'Player Intro', link: 'player_brief' },
        { text: 'Player Settings', link: 'player_settings' },
        { text: 'Player Orientation', link: 'player_orientation' },
        { text: 'Same-Screen Multi-Screen', link: 'sync_play' },
      ]
    },
    {
      text: 'Admin Manual',
      collapsed: false,
      items: [
        {
          text: 'Programme Management',
          collapsed: false,
          items: [
            { text: 'Programme Intro', link: 'cast_brief' },
            {
              text: 'Create Programme',
              collapsed: false,
              items: [
                { text: 'Create From Zero', link: 'cast_create_from_start' },
                { text: 'Create From Template', link: 'cast_create_from_template' },
                { text: 'Copy From ID', link: 'cast_create_from_id' }
              ]
            },
            { text: 'Programme Parameter', link: 'cast_paras' },
            {
              text: 'Child Screen Edit',
              collapsed: false,
              items: [
                { text: 'Child Screen Intro', link: 'child_screen_brief' },
                { text: 'Child Screen Edit', link: 'child_screen_edit' },
                { text: 'Child Screen Parameters', link: 'child_screen_paras' }
              ]
            },
            {
              text: 'Media Management',
              collapsed: false,
              items: [
                { text: 'Media Intro', link: 'media_brief' },
                { text: 'Media Edit', link: 'media_edit' },
                {
                  text: 'Media Type',
                  collapsed: false,
                  items: [
                    { text: 'Intro', link: 'media_type_intro' },
                    { text: 'Image', link: 'media_type_image' },
                    { text: 'Video', link: 'media_type_video' },
                    { text: 'Music', link: 'media_type_audio' },
                    { text: 'Text', link: 'media_type_text' },
                    { text: 'Html', link: 'media_type_web' },
                    { text: 'PDF', link: 'media_type_pdf' },
                    { text: 'Builtin Widget', link: 'media_type_widget' },
                    { text: 'Child Programme', link: 'media_type_child_cast' }
                  ]
                }
              ]
            }
          ]
        },
        {
          text: 'Relation Management',
          collapsed: false,
          items: [
            { text: 'Relation Intro', link: 'relation_brief' },
            { text: 'Cast', link: 'relation_create' },
            { text: 'Play Plan', link: 'relation_config' }
          ]
        },
        {
          text: 'Device Management',
          collapsed: false,
          items: [
            { text: 'Device Intro', link: 'device_brief' },
            { text: 'Device Auth', link: 'device_auth' },
          ]
        },
      ]
    },
    {
      text: 'FAQ',
      collapsed: false,
      items: [
        { text: 'How To Auto Start', link: 'faq_auto_start' },
      ]
    },
  ]
}

function sidebarDev(): DefaultTheme.SidebarItem[] {
  return [
    {
      text: 'Introduction',
      link: 'intro'
    },
    {
      text: 'API',
      link: 'api'
    },
    {
      text: 'Central Control Protocol',
      link: 'websocket'
    },
    {
      text: 'Device Attribute API',
      link: 'device_attr'
    }
  ]
}

function sidebarReference(): DefaultTheme.SidebarItem[] {
  return [
    {
      text: 'Reference',
      items: [
        { text: 'Site Config', link: 'site-config' },
        { text: 'Frontmatter Config', link: 'frontmatter-config' },
        { text: 'Runtime API', link: 'runtime-api' },
        { text: 'CLI', link: 'cli' },
        {
          text: 'Default Theme',
          base: '/reference/default-theme-',
          items: [
            { text: 'Overview', link: 'config' },
            { text: 'Nav', link: 'nav' },
            { text: 'Sidebar', link: 'sidebar' },
            { text: 'Home Page', link: 'home-page' },
            { text: 'Footer', link: 'footer' },
            { text: 'Layout', link: 'layout' },
            { text: 'Badge', link: 'badge' },
            { text: 'Team Page', link: 'team-page' },
            { text: 'Prev / Next Links', link: 'prev-next-links' },
            { text: 'Edit Link', link: 'edit-link' },
            { text: 'Last Updated Timestamp', link: 'last-updated' },
            { text: 'Search', link: 'search' },
            { text: 'Carbon Ads', link: 'carbon-ads' }
          ]
        }
      ]
    }
  ]
}
